import java.util.Stack;
//最小栈
public class MinStack { //入栈
    //stack入所有元素
    //将入栈元素与minStack栈顶元素比较，如果小于等于或者栈为空则入栈
    //出栈
    //stack正常出，将出栈元素与minStack的栈顶元素比较，如果相同就出栈
    Stack<Integer> stack;
    Stack<Integer> minStack;

    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if (minStack.empty()) {
            minStack.push(val);
        } else {
            if (minStack.peek() >= val) {
                minStack.push(val);
            }
        }
    }

    public void pop() {
        if (!stack.empty()) {
            int ret = stack.pop();
            if (ret == minStack.peek()) {
                minStack.pop();
            }
        }
    }

    //获取正常栈栈顶元素
    public int top() {
        if (stack.empty()) {
            return -1;
        }
        return stack.peek();
    }

    //获取最小栈栈顶元素
    public int getMin() {
        if (minStack.empty()) {
            return -1;
        }
        return minStack.peek();

    }
}